
enum DIR {
    //% block="前进"
    1,
    //% block="后退"
    2,
    //% block="左转"
    3,
    //% block="右转"
    4
}
enum MOTOR{
    //% block="左边"
    1,
    //% block="右边"
    2,
    //% block="全部"
    3

}
enum SIDE{
    //% block="左边"
    1,
    //% block="右边"
    2
}




//% color="#40E0D0" iconWidth=50 iconHeight=40
namespace CuteBot {
     
    
    //% block="设置机器人[DIR] 速度[SPEED]" blockType="command"
    //% DIR.shadow="dropdown" DIR.options="DIR" DIR.defl="DIR.前进"
    //% SPEED.shadow="range" SPEED.params.min=0    SPEED.params.max=255    SPEED.defl=200
    export function spot(parameter: any, block: any) {
        let dir = parameter.DIR.code;
        let speed = parameter.SPEED.code;
        if(dir == '1'){
            Generator.addCode(`analogWrite(3, 0);\t\n  analogWrite(5, ${speed});\t\n  analogWrite(6, 0);\t\n  analogWrite(9, ${speed});\t\n`);
            
        }else if (dir == '2'){
            Generator.addCode(`analogWrite(3, ${speed});\t\n  analogWrite(5, 0);\t\n  analogWrite(6, ${speed});\t\n  analogWrite(9, 0);\t\n`);
        }else if(dir == "3"){
            Generator.addCode(`analogWrite(3, 0);\t\n  analogWrite(5, ${speed});\t\n  analogWrite(6,${speed});\t\n  analogWrite(9, 0);\t\n`);            
        }else{
            Generator.addCode(`analogWrite(3, ${speed});\t\n  analogWrite(5, 0);\t\n  analogWrite(6, 0);\t\n  analogWrite(9, ${speed});\t\n`);
        }
        
        
        
    }

    //% block="设置[SIDE]电机 速度[SPEED]" blockType="command"
    //% SIDE.shadow="dropdown" SIDE.options="SIDE" SIDE.defl="SIDE.左边"
    //% SPEED.shadow="range" SPEED.params.min=0    SPEED.params.max=255    SPEED.defl=200
    export function side(parameter: any, block: any) {
        let side = parameter.SIDE.code;
        let speed = parameter.SPEED.code;
        if(side == '1'){
            Generator.addCode(`analogWrite(6, 0);\t\n  analogWrite(9, ${speed});`);
            
        }else {
            Generator.addCode(`analogWrite(3, 0);\t\n  analogWrite(5, ${speed});`);
        }
         
    }

    //% block="[MOTOR]电机停止 " blockType="command"
    //% MOTOR.shadow="dropdown" MOTOR.options="MOTOR" MOTOR.defl="MOTOR.左边"
    export function STOP(parameter: any, block: any) {
        let motor = parameter.MOTOR.code;
        if(motor == '1'){
            Generator.addCode(` analogWrite(6, 0);\t\n  analogWrite(9, 0);`);
           
        }else if (motor == '2'){
            Generator.addCode(`analogWrite(3, 0);\t\n  analogWrite(5, 0);`);
        }else{
            Generator.addCode(`analogWrite(3, 0);\t\n  analogWrite(5, 0);\t\n  analogWrite(6, 0);\t\n  analogWrite(9, 0);\t\n`);
        }
        
        
        
    }


  


}
